package cn.main.entity.sys;

import com.mysql.jdbc.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;
import java.util.UUID;

/**
 * Author: chengwei
 * Date:   2016/7/12
 * Time:   17:38
 */
@Entity
@Table(name = "sys_column")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class SysColumn implements Serializable {

    private static final long serialVersionUID = -81186855830480071L;
    @Id
    @Column(name = "column_id")
    private String columnId;
    
    @Column(name = "name")
    private String name;
    
    @Column(name = "show_order")
    private int showOrder;
    
    @OneToMany(mappedBy = "column")
    private Set<SysFunction> functions;

    public String getColumnId() {
        if (StringUtils.isNullOrEmpty(columnId)){
            columnId = UUID.randomUUID().toString().replace("-","");
        }
        return columnId;
    }

    public void setColumnId(String columnId) {
        this.columnId = columnId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getShowOrder() {
        return showOrder;
    }

    public void setShowOrder(int showOrder) {
        this.showOrder = showOrder;
    }

    public Set<SysFunction> getFunctions() {
        return functions;
    }

    public void setFunctions(Set<SysFunction> functions) {
        this.functions = functions;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        SysColumn sysColumn = (SysColumn) o;

        return !(getColumnId() != null ? !getColumnId().equals(sysColumn.getColumnId()) : sysColumn.getColumnId() != null);

    }

    @Override
    public int hashCode() {
        return getColumnId() != null ? getColumnId().hashCode() : 0;
    }
}
